package utils;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

public class FileUtils {

    /**
     * Method checking if the specified file exist
     * @param pathToFile relative path to the file
     * @return true if the file exist, false otherwise
     */
    public static boolean fileExist(String pathToFile) {
        File fileToTest = new File(pathToFile);
        return fileToTest.exists();
    }
    
    /**
     * Method reading the specified file and returning it content
     * @param pathToFile relative path to the file to read
     * @return String Containing the full content of the specified file
     */
    public static String getFileContent(String pathToFile) {
        String content  = "";
        File fileToRead = new File(pathToFile);
        FileInputStream fis;
        DataInputStream dis;
        BufferedReader br;
        
        try {
            fis = new FileInputStream(fileToRead);
            dis = new DataInputStream(fis);
            br  = new BufferedReader(new InputStreamReader(dis));
            
            String line;
            while ((line = br.readLine()) != null) {
                content += line;
            }
        } catch (FileNotFoundException e) {
            System.out.println("FileUtils : file " + pathToFile + " not found");
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        return content;
    }
}
